#opendir(DH,"/home/uec-00/yapingli/code/SNP/") or die;
opendir(DH,"/Users/yaping/Documents/workspace/perl_script/") or die;
my @out;
foreach my $file(readdir(DH)){
	if($file=~/normal-(\d+)-(\d+)-(\d+)-(\d+)-(\S+)\.o*/){
		my $mapq = $1;
		my $baseq = $2;
		my $seq_cov = $3;
		my $allele_count = $4;
		my $allele_freq = $5;
		#open(FH,"</home/uec-00/yapingli/code/SNP/$file") or die;
		open(FH,"</Users/yaping/Documents/workspace/perl_script/$file") or die;
		my @in=<FH>;
		chomp(@in);
		close(FH);
		my $ag_count=0;
		my $total_count=0;
		my $snp_het=0;
		my $snp_hom=0;
		my $seq_het=0;
		my $seq_hom=0;
		my $true_pos=0;
		my $true_neg=0;
		my $fp=0;
		my $fn=0;
		my $total_snp=1150448;
		foreach my $line(@in){
			if($line=~/\d+\tA\tB\t[ATCG]\t[ATCG]/){
				$total_count++;
			}
			if($line=~/\d+\tA\tB\tA\tG/ or $line=~/\d+\tA\tB\tG\tA/ or $line=~/\d+\tA\tB\tT\tC/ or $line=~/\d+\tA\tB\tC\tT/){
				$ag_count++;
			}
			if($line=~/heterozygous loci in 1M SNP array is: (\d+)/){
				$snp_het = $1;
			}
			if($line=~/homozygous loci in 1M SNP array is: (\d+)/){
				$snp_hom = $1;
			}
			if($line=~/heterozygous loci in sequencing is: (\d+)/){
				$seq_het = $1;
			}
			if($line=~/homozygous loci in sequencing is: (\d+)/){
				$seq_hom = $1;
			}
			if($line=~/true positive number is: (\d+)/){
				$true_pos = $1;
			}
			if($line=~/true negative number is: (\d+)/){
				$true_neg = $1;
			}
			if($line=~/false positive rate is: (\d+\.\d+)/){
				$fp = $1;
			}
			if($line=~/false negative rate is: (\d+\.\d+)/){
				$fn = $1;
			}
		}
		my $err=$fp+$fn;
		my $portion=($snp_het+$snp_hom)/$total_snp;
		my $other_count=$total_count-$ag_count;
		push(@out,"normal\t$mapq\t$baseq\t$seq_cov\t$allele_count\t$allele_freq\t$err\t$portion\t$fp\t$fn\t$ag_count\t$other_count\t$snp_het\t$snp_hom\t$seq_het\t$seq_hom\t$true_pos\t$true_neg\n");
	}
}
closedir(DH);
#open(OUT,">/home/uec-00/yapingli/code/SNP/normal_snp_summary.txt");
open(OUT,">/Users/yaping/Documents/workspace/perl_script/normal_snp_summary.txt");
print OUT @out;
close(OUT);

